home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
hity wydania
/
Ubuntu 9.10 PL
/
karmelkowy-koliberek-desktop-9.10-i386-PL.iso
/
casper
/
filesystem.squashfs
/
usr
/
share
/
jockey
/
jockey-backend
next >
Wrap
Text File
|
2008-11-24
|
3KB
|
76 lines
#!/usr/bin/python
# (c) 2008 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''Jockey D-BUS backend executable.'''
import sys, optparse, logging, gettext
import jockey.backend
from jockey.oslib import OSLib
def parse_argv():
'''Parse command line arguments, and return (options, args) pair.'''
parser = optparse.OptionParser()
parser.add_option ('--debug', action='store_true',
dest='debug', default=False,
help=_('Enable debugging messages.'))
parser.add_option ('-l', '--logfile', type='string', metavar='FILE',
dest='logfile', default=None,
help=_('Write logging messages to a file instead to stderr.'))
parser.add_option ( '--timeout', type='int',
dest='timeout', metavar='SECS', default=600,
help=_('Timeout for D-BUS service (default: 600, 0: run forever)'))
parser.add_option ('-H', '--handler-dir',
type='string', dest='handler_dir', metavar='DIR', default=None,
help=_('Add a custom handler directory.'))
parser.add_option ( '--test', action='store_true',
dest='test', default=False,
help=_('Run on session D-BUS (only for testing)'))
(opts, args) = parser.parse_args()
return (opts, args)
def setup_logging(debug=False, logfile=None):
'''Setup logging.'''
logging.raiseExceptions = False
if debug:
logging.basicConfig(level=logging.DEBUG, filename=logfile,
format='%(asctime)s %(levelname)s: %(message)s')
else:
logging.basicConfig(level=logging.WARNING, filename=logfile,
format='%(levelname)s: %(message)s')
gettext.install('jockey', unicode=True)
argv_options, argv_args = parse_argv()
setup_logging(argv_options.debug, argv_options.logfile)
if argv_options.test:
OSLib.inst = OSLib()
svr = jockey.backend.Backend.create_dbus_server(session_bus=True,
handler_dir=argv_options.handler_dir)
else:
OSLib.inst = OSLib()
svr = jockey.backend.Backend.create_dbus_server(
handler_dir=argv_options.handler_dir)
if argv_options.timeout == 0:
svr.run_dbus_service()
else:
svr.run_dbus_service(argv_options.timeout)